function [error_5d, mean_error_5d, std_error_5d] = Model_5d_wrapper_toolbox(patient)
    
    
    %| 5D model wrapper for Modelfit_5d_toolbox.m code
    %| If model parameters exist, ask user if you want to rerun
    %(overwriting the previous parameters and error).
    %------------------------------------------------------------------------
    %|      Dependancies;
    %|                  Modelfit_5d_toolbox.m
    %|
    %|
    %------------------------------------------------------------------------
    %   This file is part of the
    %   5D-Novel4DCT Toolbox  ("Novel4DCT-Toolbox")
    %   DH Thomas, Ph.D
    %   University of California, Los Angeles
    %   Contact: mailto:dhthomas@mednet.ucla.edu
    %------------------------------------------------------------------------
    % $Author: DHThomas $	$Date: 2014/04/01 10:23:59 $	$Revision: 0.1 $
    
%     if nargin < 2
%         patient.par_toolbox = 0;
%         
%     end
%     patient.model_params_folder = [patient.model_folder '/model_params'];
    mkdir(patient.model_params_folder);
    params_dir = dir(patient.model_params_folder);
    params_dir(1:2) = [];
    
    str = 'Y'; %default is to continue
    if size(params_dir,1)>patient.dim(1)*3;
        prompt = 'Model Parameters exist. \n                Do you want to re-run 5D Model? Y [Hit Return for N]: ';
        str = input(prompt,'s');
        if isempty(str)
            str = 'N';
        end
    end
    if strcmpi('Y', str)>0;str = 'Y';else str = 'N';end
    if str == 'N'
        display('Loading existing mean 5D Error matrix...')
        load([patient.model_folder sprintf('/error_5d_ref%d',patient.ref)])
    else
        
        save_files = 1; % If save_files==1, values of x0, alpha and beta saved to disk;
        step = 1; % choose resolution at which to run the model;
        
        ii = 1:step:patient.dim(1);
        jj = 1:step:patient.dim(2);
        kk = 1:step:patient.dim(3);
        
        tic
        if patient.par_toolbox>0
            
            [error_5d] = Modelfit_5d_parfor_toolbox(patient,ii,jj,kk,save_files, 1);
        else
            [error_5d] = Modelfit_5d_toolbox(patient,ii,jj,kk,save_files);
        end
        
        display('Saving model error...')
        save([patient.model_folder sprintf('/error_5d_ref%d',patient.ref)], 'error_5d')
        
        
    end
    
    mean_error_5d=nanmean(error_5d(patient.static_mask(:)>0));
   std_error_5d=nanstd(error_5d(patient.static_mask(:)>0));
    
    pm = char(177);
    display(sprintf('   Mean 5D Error = %.2f %c %.2f mm',mean_error_5d, pm ,std_error_5d))
